package com.woniuxy.cloud.depositassembly.controller;

import com.woniuxy.cloud.api.DepositQueryAPI;
import com.woniuxy.cloud.api.param.BackDepositParam;
import com.woniuxy.cloud.demo.Result;
import com.woniuxy.cloud.depositassembly.service.DepositOrderService;
import com.woniuxy.cloud.api.param.DepositReduceParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @author 周川雄
 * @date 2022/2/11 15:27
 */
@RestController
@Slf4j
public class DepositQueryAPIImpl implements DepositQueryAPI {


    @Resource
    private DepositOrderService orderService;

    /**
     * 支付,该方法不可使用
     * @param id
     * @return
     */
    @Override
    public Result payDeposit(Integer id) {

        if (orderService.payDeposit(id))
            return Result.newInstance().setCode(200).setMsg("支付成功");
        else {
            return Result.newInstance().setCode(500).setMsg("支付失败");
        }
    }

    @Override
    public Result<String> penalty(DepositReduceParam param) {
        return Result.newInstance().setCode(200).setMsg("罚款成功").setData(orderService.penalty(param));
    }

    /**
     * 支付接口，不走网关
     * @param depositOrderId
     * @return
     */
    @GetMapping(value = "/alipayDeposit",produces = "text/html;charset=UTF-8")
    public String alipayDeposit(@RequestParam Integer depositOrderId){
        return orderService.alipayDeposit(depositOrderId);
    }
}
